package com.sita.linboard.person;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.sita.linboard.R;
import com.sita.linboard.base.BaseActivity;
import com.sita.linboard.base.BaseApplication;
import com.sita.linboard.http.RestClient;
import com.sita.linboard.utils.Constants;
import com.sita.linboard.utils.SpUtils;
import com.sita.linboard.wallet.BalanceRequest;

import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
 * Created by Jason on 2016/9/19.
 */
public class DriverTripActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {
    private SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView driveTrip;
    private DriveTripAdapter adapter;
    private DriverTripBackBean data;
    private LinearLayout back;
    private TextView head_title;
    private ProgressBar progressBar;
    @Override
    protected void initData() {
        head_title.setText("行程订单");
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        driveTrip.setLayoutManager(linearLayoutManager);
        driveTrip.setAdapter(adapter);
        swipeRefreshLayout.setOnRefreshListener(this);
        getDatafromSer();
    }
    @Override
    protected void initView(Bundle savedInstanceState) {
          driveTrip = bindView(R.id.driver_trip);
          adapter = new DriveTripAdapter(this);
          back = bindView(R.id.img_back);
          progressBar = bindView(R.id.dirver_bar);

        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        head_title = bindView(R.id.head_title);
        head_title.setVisibility(View.VISIBLE);
        swipeRefreshLayout  = bindView(R.id.swiplayout);
    }
  private void getDatafromSer(){
      BalanceRequest request = new BalanceRequest();
      request.driver_id = SpUtils.getString("AccoundID",null, BaseApplication.getContext());
      RestClient.getRestService().DriverTrip(request, new Callback<DriverTripBackBean>() {
          @Override
          public void success(DriverTripBackBean driverTripBackBean, Response response) {
              if (driverTripBackBean.getErrorCode().equals("0")){
                  data = driverTripBackBean;
                  adapter.setData(data,progressBar);
              }
          }

          @Override
          public void failure(RetrofitError error) {

          }
      });
  }
    @Override
    protected int getId() {
        return R.layout.activity_drivetrip;
    }

    public static void DriverTripIntent(Context context){
        Intent intent  = new Intent(context,DriverTripActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void onRefresh() {
        getDatafromSer();
        swipeRefreshLayout.setRefreshing(false);
    }
}
